import java.io.*;

public class testDemo {
    public static void main(String[] args) throws IOException {
        //    源文件地址
        File in = new File("D:\\文档\\JAVA\\Product\\JavaDemo1\\src");
        //    目标地址
        File out = new File("D:\\文档\\JAVA\\Product\\JavaTest\\src");


        //使用递归来读取全部文件

        copy(in, out,"");


    }

    private static void copy(File in, File out,String name) throws IOException {


        if (in.isFile()) {
            //如果是文件要创建
            FileInputStream fis = new FileInputStream(in);
            FileOutputStream fos = new FileOutputStream(out + "\\" + name.split("\\.")[0] + ".java");
            byte[] buf = new byte[1024];
            int len;
            while ((len = fis.read(buf)) != -1) {
                fos.write(buf, 0, len);
            }
            fis.close();
            fos.close();
        } else {
            //    如果是文件夹

            out = new File(out + "\\" + name);
            out.mkdirs();
            File[] ins = in.listFiles();
            //循环in
            for (File f : ins) {
                copy(f, out,f.getName());
            }
        }


    }
}